<?php

class bobFileOpenDialog extends GtkFileChooserDialog {
	public function __construct($parent) {
		parent::__construct(Gtk::FILE_CHOOSER_ACTION_OPEN);
		
		if(bob::$fileOpenLastDir) {
			$this->set_current_folder(
				bob::$fileOpenLastDir		
			);
		}

		$this->set_transient_for($parent);
		$this->set_modal(true);
		$this->set_position(Gtk::WIN_POS_CENTER);
		$this->set_title("Open File...");		
		$this->set_select_multiple(true);
		$this->add_buttons(array(
			Gtk::STOCK_CANCEL,Gtk::RESPONSE_CANCEL,
			Gtk::STOCK_OPEN,Gtk::RESPONSE_ACCEPT
		));

		$this->show_all();
		$response = $this->run();
		$this->hide();
		
		if($response == Gtk::RESPONSE_ACCEPT) {
			$this->file = $this->get_filenames();
		} else {
			$this->file = null;
		}
		
		bob::$fileOpenLastDir = $this->get_current_folder();

		return;
	}
}

class bobFileSaveDialog extends GtkFileChooserDialog {
	public function __construct($parent) {
		parent::__construct(Gtk::FILE_CHOOSER_ACTION_SAVE);
		
		if(bob::$fileOpenLastDir) {
			$this->set_current_folder(
				bob::$fileOpenLastDir		
			);
		}

		$this->set_transient_for($parent);
		$this->set_modal(true);
		$this->set_position(Gtk::WIN_POS_CENTER);
		$this->set_title("Save File...");		
		$this->add_buttons(array(
			Gtk::STOCK_CANCEL,Gtk::RESPONSE_CANCEL,
			Gtk::STOCK_SAVE,Gtk::RESPONSE_ACCEPT
		));

		$this->show_all();
		$response = $this->run();
		$this->hide();
		
		if($response == Gtk::RESPONSE_ACCEPT) {
//			$this->file = $this->get_current_folder()."/".$this->get_filename();
			$this->file = $this->get_filename();
		} else {
			$this->file = null;
		}
		
		bob::$fileOpenLastDir = $this->get_current_folder();

		return;
	}
}

class bobModalDialog extends GtkDialog {
	public function __construct($parent) {
		parent::__construct();
		$this->set_transient_for($parent);
		$this->set_modal(true);
		$this->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
		$this->set_has_separator(false);
		
		$this->connect_simple('delete-event',array($this,'response'),Gtk::RESPONSE_CANCEL);
		return;
	}
}

class bobWarnUnsavedDialog extends bobModalDialog {
	public function __construct($parent) {
		parent::__construct($parent);

		$this->accept = false;
		$this->save = false;

		$this->message = new GtkLabel('Are you sure you want to close this '.
			'file? It has not yet been saved, you will lose all changes.');
		
		$this->add_buttons(array(
			Gtk::STOCK_CANCEL, Gtk::RESPONSE_CANCEL,
			Gtk::STOCK_OK, Gtk::RESPONSE_ACCEPT,
			Gtk::STOCK_SAVE, Gtk::RESPONSE_HELP
		));
				
		$this->vbox->pack_start($this->message);		

		$this->show_all();		
		$choice = $this->run();
		$this->hide();
		
		if($choice == Gtk::RESPONSE_ACCEPT) {
			$this->accept = true;
		}
		else if($choice == Gtk::RESPONSE_HELP) {
			$this->save = true;
			$this->accept = true;
		}
						
		return;
	}
}

?>